/**
 * populates the selectbox(elementId) with the response
 *
 * useful when the cities select box needs to be populated according to state selected
 */
populateSelectBox = function(elementId,method,url,data){
    var $element = $('#'+elementId+'');
    $.ajax({
        type: method,
        url: url,
        data: data,
        dataType: "json",
        success: function (data) {
            $element.empty();
            $element.append('<option value="">Select</option>');
            $.each(data, function (key,value) {
                $element.append('<option value="'+key+'">'+value+'</option>');
            });
        },
        beforeSend: function(){
            $element.addClass('show_loading_in_center')
        },
        complete: function(){
            $element.removeClass('show_loading_in_center')
        }
    });
}

/**
 * Returns a particular URL variable's value or all the variable's values as an array.
 * It is an addition to the jQuery's namespace.
 */
$.extend({
    getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlVar: function(name){
        return $.getUrlVars()[name];
    }
});

/**
  * vote
  *
  * param string url The url to send for response
  * param mixed data The variables that are to be send
  * author Gaurav Sharma, Created on 25 January 2010 10:31 PM
  */
vote = function(url,data){
    $.ajax({
        type: 'get',
        url: url,
        data: data,
        dataType: 'html',
        success: function(data)
        {
            $responseDiv
            .empty()
            .html(data)
            .show();
        },
        beforeSend: function()
        {
            $loadingDiv.text('Please wait').addClass('show_loading_in_right')
        },
        complete: function()
        {
            $loadingDiv.text("").removeClass('show_loading_in_right')
        }
    });
}